package com.mikey.lock8;

import java.util.concurrent.TimeUnit;

/**
 * @author :Mikey
 * @description :
 * 3,增加一个普通方法，之后，先执行普通方法。
 * 4，两个对象，，，
 * @create :2022-09-20 15:18:00
 */
public class Test1 {
    public static void main(String[] args) {
        //两个对象
        Phone1 phone1 = new Phone1();
        Phone1 phone2 = new Phone1();
        new Thread(() -> {
            phone1.sendMsg();
        }, "A").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(() -> {
            phone2.call();
        }, "B").start();
    }
}

class Phone1 {
    public synchronized void sendMsg() {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("发短信");
    }

    public synchronized void call() {
        System.out.println("打电话");
    }
    //没有锁，不是同步方法，不受锁的影响
    public  void hello() {
        System.out.println("hello");
    }
}

